#include "classes/ContentManager.hpp"
#include "JDD/classes/DataManager.hpp"
void ContentManager::AddDesciption(std::string theText, int theTheme)
{
    typeDescription anDesciption;
    anDesciption.Desciption=theText;
    anDesciption.Theme=theTheme;
    mDesciptions.push_back(anDesciption);
}
void ContentManager::AddItem(std::string theName, std::string theInfo, std::string theGrade, std::string theType, std::string theSubType, std::string theTwohanded, std::string theStackable, std::string thePower)
{
    typeItem newItem;
    newItem.Name=theName;
    newItem.Info=theInfo;
    newItem.Grade=theGrade;
    newItem.Type=theType;
    newItem.SubType=theSubType;
    newItem.TwoHanded=theTwohanded;
    newItem.Stackable=theStackable;
    newItem.Power=thePower;
    mItems.push_back(newItem);
}
std::string ContentManager::GetRandDescription(int theTheme)
{
    unsigned int anIndex=0;
    int anRand;
    std::vector<typeDescription> anList;
    for(anIndex=0; anIndex<mDesciptions.size(); anIndex++)
    {
        if(mDesciptions[anIndex].Theme==theTheme)
        {
            anList.push_back(mDesciptions[anIndex]);
        }
    }
    int size=anList.size();
    anRand=sf::Randomizer::Random(0,size-1);
	return anList[anRand].Desciption;
}
typeItem ContentManager::GetRandItem()
{
    int size=mItems.size();
    int anRand=sf::Randomizer::Random(0,size-1);
	return mItems[anRand];
}
typeItem ContentManager::GetRandItem(std::string theType)
{
    unsigned int anIndex=0;
    int anRand;
    std::vector<typeItem> anList;
    for(anIndex=0; anIndex<mItems.size(); anIndex++)
    {
        if(mItems[anIndex].Type==theType)
        {
            anList.push_back(mItems[anIndex]);
        }
    }
    int size=anList.size();
    anRand=sf::Randomizer::Random(0,size-1);
	return anList[anRand];
}
typeItem ContentManager::GetRandItem(std::string theType,std::string theGrade)
{
    unsigned int anIndex=0;
    int anRand;
    std::vector<typeItem> anList;
    for(anIndex=0; anIndex<mItems.size(); anIndex++)
    {
        if(mItems[anIndex].Type==theType && mItems[anIndex].Grade==theGrade)
        {
            anList.push_back(mItems[anIndex]);
        }
    }
    int size=anList.size();
    anRand=sf::Randomizer::Random(0,size-1);
    return anList[anRand];
}
typeItem ContentManager::GetItem(std::string theName)
{
    unsigned int anIndex=0;
    typeItem anItem;
    anItem.Name="Not Found";
    for(anIndex=0; anIndex<mItems.size(); anIndex++)
    {
        if(mItems[anIndex].Name==theName)
        {
            anItem=mItems[anIndex];
            break;
        }
    }
    return anItem;
}
void ContentManager::LoadList(std::string theFileName)
{
    JDD::DataManager anLoader;
    anLoader.LoadRaw(theFileName);
    JDD::typeData anData;
    while(!anLoader.isEmpty())
    {
        anData=anLoader.PullData();
        if(anData.Name=="Desc" && anData.Values.size()>=2)
        {
            AddDesciption(anData.Values[0], JDD::StringToInt(anData.Values[1]));
        }
		else if(anData.Name=="Item" && anData.Values.size()>=7)
		{
            AddItem(anData.Values[0],anData.Values[1],anData.Values[2],anData.Values[3],anData.Values[4],anData.Values[5],anData.Values[6], anData.Values[7]);
		}
    }
}
